package com.tianfang.mytranmqproducer.controller;

import com.tianfang.mytranmqproducer.common.params.MailParam;
import com.tianfang.mytranmqproducer.service.MQProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class MailController {
    @Autowired
    private MQProducerService mqProducerService;

    @RequestMapping("sendMailApi")
    public String sendMail(HttpServletRequest request, Model model){
        String sendTo = request.getParameter("sendTo");
        // 邮件发送
        MailParam mail = new MailParam();
        mail.setTo(sendTo);
        mail.setSubject("ActiveMQ测试");
        mail.setContent("通过ActiveMQ异步发送邮件！");
        mqProducerService.sendMessage(mail);
        model.addAttribute("msg","发送到消息队列成功");
        //转发
        return "sendMail";
    }
}
